package com.eelye.util.http;

import com.eelye.util.http.enums.RequestMethodEnum;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public interface EasyHttpClient {

    void setProxy(String ip, int port);

    /**
     *
     * @param method
     * @param uri
     * @param body
     * @param headers
     * @param returnType 要返回的类型的类
     * @return
     * @throws IOException
     */
    <T> T request(RequestMethodEnum method , String uri, String body, Map<String, String> headers, Class<T> returnType)
            throws IOException;

    default String post(String uri, String body, Map<String, String> headers) throws IOException{
        return request(RequestMethodEnum.Post, uri, body, headers, String.class);
    }

    default String get(String uri) throws IOException{
        return request(RequestMethodEnum.Get, uri, "", new HashMap<>(), String.class);
    }

    default String get(String uri, Map<String, String> headers) throws IOException{
        return request(RequestMethodEnum.Get, uri, "", headers, String.class);
    }

    default <T> T request(String uri, Class<T> returnType) throws IOException{
        return request(RequestMethodEnum.Get, uri, "", Collections.emptyMap(), returnType);
    }

    void close();

    default String getCookie(String key) {
        throw new RuntimeException("未实现");
    }
}
